package xdu.lz.stage1_basic.chapter2_api.d_join_interrupt_wait;

class CaptureRunnable implements Runnable{

    private String machineName;

    private long spendTime;

    public CaptureRunnable(String machineName, long spendTime) {
        this.machineName = machineName;
        this.spendTime = spendTime;
    }

    @Override
    public void run() {
        try {
            Thread.sleep(spendTime);
            System.out.println(machineName+" captured data completed at timestap "+System
                    .currentTimeMillis());
        } catch (InterruptedException e) {
            e.printStackTrace();

        }
    }
}
public class Code05_JoinDemo {
    public static void main(String[] args) throws InterruptedException {
        System.out.println("开始采集:"+System.currentTimeMillis());
        Thread m1 = new Thread(new CaptureRunnable("M1", 5000L));
        Thread m2 = new Thread(new CaptureRunnable("M2", 3000L));
        Thread m3 = new Thread(new CaptureRunnable("M3", 1000L));
        m1.start();
        m2.start();
        m3.start();
        m1.join();
        m2.join();
        m3.join();
        System.out.println("采集结束:"+System.currentTimeMillis());
    }
}
